Macromedia Flex Article

Learning Flex Basics (Part 1): Creating Your First Flex Application


Table of Contents

  1. Introduction
  2. A Brief Overview of Macromedia Flex
  3. Building the Application
  4. Create the Application Object
  5. Add a Panel for the Application Layout
  6. Add a Label for the View Header
  7. Add an Array of Objects to Define the Coffee Blends
  8. Add a ComboBox to Display the Coffee Blends
  9. Add a Text Control to Display the Description
  10. Add a Button to Add a Coffee Blend to the Shopping Cart
  11. Add a List Control for the Shopping Cart
  12. Add a Script to Handle the Button Click Event
  13. Complete Code Listing for firstapp.mxml
  14. Where to Go From Here

Complete Code Listing for firstapp.mxml

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" >
	<!-- data model -->
	<mx:Array id="coffeeArray">
		<mx:Object>
			<label>Red Sea</label>
			<data>Smooth and fragrant</data>
		</mx:Object>
		<mx:Object>
			<label>Andes</label>
			<data>Rich and pungent</data>
		</mx:Object>
		<mx:Object>
			<label>Blue Mountain</label>
			<data>Delicate and refined</data>
		</mx:Object>
	</mx:Array>
	<mx:Script>
		<![CDATA[
			function addToCart():Void
			{
				cart.addItem(coffeeCombo.selectedItem.label,coffeeCombo.selectedItem.data);
			}
		]]>
	</mx:Script>
	<!-- view -->
	<mx:Panel title="My First Flex App">
		<mx:Label text="Coffee Blends"/>
		<mx:ComboBox id="coffeeCombo" dataProvider="{coffeeArray}"/>
		<mx:Text text="Description: {coffeeCombo.selectedItem.data}"/>
		<mx:Button label="Add to Cart" click="addToCart()"/>
		<mx:List id="cart"/>
	</mx:Panel>
</mx:Application>